package com.jdzy.student.controller;

import com.jdzy.model.common.vos.ResultA;
import com.jdzy.model.common.vos.ResultCodeEnum;
import com.jdzy.model.teacher.dtos.AssginMenuDto;
import com.jdzy.student.service.SysRoleMenuService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Slf4j
@Api(value = "角色菜单的controller类")
@CrossOrigin(allowCredentials = "true" , allowedHeaders = "*")
@RequestMapping(value = "/api/system/sysRoleMenu")
public class SysRoleMenuController {
    @Autowired
    private SysRoleMenuService sysRoleMenuService ;
    //   1. 根据角色id查询菜单列表--查询所有菜单
    @GetMapping(value = "/findSysRoleMenuByRoleId/{roleId}")
    public ResultA<Map<String , Object>> findSysRoleMenuByRoleId(@PathVariable(value = "roleId") Long roleId) {
        //查询分配角色菜单列表
        Map<String , Object> sysRoleMenuList = sysRoleMenuService.findSysRoleMenuByRoleId(roleId) ;
        return ResultA.build(sysRoleMenuList , ResultCodeEnum.SUCCESS) ;
    }
    //2. 根据角色id分配菜单--保存菜单--提交按钮
    @PostMapping(value = "/doAssign")
    public ResultA doAssign(@RequestBody AssginMenuDto assginMenuDto) {
        sysRoleMenuService.doAssign(assginMenuDto);
        return ResultA.build(null , ResultCodeEnum.SUCCESS) ;
    }

}
